package com.bolong.gmgc.timer;

import java.sql.ResultSet;
import java.sql.SQLException;  
  

public class Demo {  
  
    private String sql = null;  
    private DBHelper db1 = null;  
    private ResultSet ret = null;  
    private DBHelper db2=null;
  
    public void  excute() {  
        sql = "select id from stopcarpark where id <>003 ";//SQL语句  
        db1 = new DBHelper(sql);//创建DBHelper对象  
        
        //要执行的sql
        String sqlexcute="INSERT INTO reconciliation "
		+" SELECT NULL ,DATE_FORMAT(b.`create_time`,'%Y-%m-%d') DATE , "
		+" SUM(b.bill_money) allmoney, "
		+" SUM(CASE WHEN (b.pay_type=5 OR b.`pay_type`=3) AND b.`bill_type`<>3 AND b.`bill_type`<>4 THEN b.`bill_money` ELSE 0 END) temp_allmoney, "
		+" SUM(CASE WHEN b.`bill_type`=4 OR b.`bill_type`=3 AND  b.`pay_type` <> 6  THEN b.`bill_money` ELSE 0 END) monthcard_allmoner, "
		+" 2, "
		+" ? "
		+" FROM bill b WHERE "
		+" (TO_DAYS(NOW())-TO_DAYS(b.`create_time`)=1) and "
		+" b.park_id=? "
		+" GROUP BY DATE_FORMAT(b.`create_time`,'%Y-%m-%d' ) ";
        db2=new DBHelper(sqlexcute);
        try {  
            ret = db1.pst.executeQuery();//执行语句，得到结果集  
            while (ret.next()) {  
            	String parkid=ret.getString("id");
            	db2.pst.setString(1, parkid);
            	db2.pst.setString(2, parkid);
            	db2.pst.execute();
            }//显示数据  
            System.out.println("完成");
            ret.close();  
            db1.close();//关闭连接  
            db2.close();
        } catch (SQLException e) {  
            e.printStackTrace();  
        }  
    }  
   public  void test(){
	   System.out.println("test");
   }
}  
